import { useEffect } from "react";
import { throttle } from "lodash";

const useTouchBottom = (handler) => {
const isTouchBottom = () => {
const showHeight = window.innerHeight;
const scrollTopHeight = document.body.scrollTop || document.documentElement.scrollTop;
const allHeight = document.body.scrollHeight;
if (allHeight <= showHeight + scrollTopHeight) {
handler();
}
};

const useFn = throttle(isTouchBottom, 500);

useEffect(() => {
window.addEventListener("scroll", useFn);
return () => {
window.removeEventListener("scroll", useFn);
};
}, []);
};

export default useTouchBottom;